package com.qfedu.mall.api.controller;


import com.qfedu.mall.beans.vo.CategoryVo;
import com.qfedu.mall.beans.vo.PidVo;
import com.qfedu.mall.beans.vo.ProductSkuVO;
import com.qfedu.mall.beans.vo.ProductVO;
import com.qfedu.mall.common.vo.PageVo;
import com.qfedu.mall.common.vo.ResultVO;
import com.qfedu.mall.common.vo.ResultVO1;
import com.qfedu.mall.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/product")
@Api(value = "提供商品信息相关接口",tags = "商品管理")
public class ProductController {
    @Autowired
    private ProductService productService;


    @GetMapping("/list")
    @ApiOperation("根据活动属性查询对应活动商品接口")
    @ApiImplicitParam(dataType = "Integer",name = "discounts", value = "折扣类型，0不打折 1一元购 2显示抢购 3满60-59 4 9.9特卖 5是否参与拼团",required = true)
    public ResultVO list(Integer discounts){
        System.out.println("discounts:"+discounts);
        return productService.selectProductByDiscounts(discounts);
    }


    /**
     * author：dyw
     * @param category
     * @return
     */
    @GetMapping("/category")
    @ApiOperation("根据商品分类查询该分类的所有商品")
    @ApiImplicitParam(dataType = "Integer",name = "category",value = "商品分类类型空值热销爆款 1女装 2鞋包 3转化护肤 4时令水果 5肉类禽蛋 6海鲜水产",required = false)
    public ResultVO productCate(CategoryVo category){
        System.out.println("contoller category:"+category);
        return productService.ProductCate(category.getCategory());
    }


    @GetMapping("/SpellList")
    @ApiOperation("拼单查询")
    public ResultVO shareBill(){

        ResultVO resultVO = productService.Pin();
        return resultVO;
    }


    @GetMapping("/goodsDetails")
    @ApiOperation("根据商品ID查询商品详细信息")
    @ApiImplicitParam(dataType = "Integer",name = "pid",value = "商品详情",required = true)
    public ResultVO detailInfo(Integer pid ){
        System.out.println("pid:" + pid);
        return productService.detailInfo(pid) ;
    }

    @GetMapping("/pinglun")
    @ApiOperation("根据商品ID查询商品评论")
    @ApiImplicitParam(dataType = "Integer",name = "pid",value = "商品评价",required = true)

    public ResultVO selectPcomments(Integer pid){

        System.out.println("-----pid:" + pid);
        return productService.selectcomments(pid) ;
    }


    @GetMapping("/shopDetails")
    @ApiOperation("图文详情图片")
    public ResultVO shopsDetail(){

        ResultVO resultVO = productService.shopDetails();

        return resultVO;
    }

    @GetMapping("/taocan")
    @ApiOperation("根据商品ID查询商品套餐")
    @ApiImplicitParam(dataType = "Integer",name = "pid",value = "商品套餐",required = true)

    public ResultVO selectProductSku(Integer pid){

        System.out.println("pid:" + pid);
        return productService.selectProductSku(pid) ;
    }
    @PostMapping(value = "/xinzengshangpin")
    @ApiOperation("新增商品")
    @ApiImplicitParam(dataType = "ProductVO",name = "productVO",value = "新增详情",required = true)
    public ResultVO insertProduct( @RequestBody ProductVO productVO) {
        System.out.println("productVO:" + productVO);
        ResultVO resultVO = productService.insertByPVO(productVO);
        return resultVO;


    }
    @PostMapping("/shanchushangpin")
    @ApiOperation("删除商品")
    @ApiImplicitParam(dataType = "Integer",name = "pid",value = "商品ID",required = true)
    public ResultVO deleteProduct(@RequestBody PidVo pid) {
        System.out.println("pid：" +pid);
        return productService.deleteByPid(pid.getPid());

    }
    @PostMapping("/xiugaishanpin")
    @ApiOperation("修改商品")
    @ApiImplicitParam(dataType = "ProductVO",name = "productVO",value = "修改商品",required = true)
    public ResultVO updateProduct(@RequestBody ProductVO productVO) {
        return productService.updateByPVO(productVO);

    }

    @PostMapping(value = "/xinzengtaocan")
    @ApiOperation("新增商品套餐")
    @ApiImplicitParam(dataType = "ProductSkuVO",name = "productSkuVO",value = "新增套餐",required = true)
    public ResultVO insertProductSku( @RequestBody ProductSkuVO productSkuVO) {
        ResultVO resultVO = productService.insertBySVO(productSkuVO);
        return resultVO;


    }
    @PostMapping("/shanchutaocan")
    @ApiOperation("删除商品套餐")
    @ApiImplicitParam(dataType = "Integer",name = "sid",value = "套餐ID",required = true)
    public ResultVO deleteProductSku( Integer sid) {

        return productService.deleteSkuByPid(sid);

    }
    @PostMapping("/xiugaitaocan")
    @ApiOperation("修改商品套餐")
    @ApiImplicitParam(dataType = "ProductSkuVO",name = "productSkuVO",value = "新增套餐",required = true)
    public ResultVO updateProductSku(@RequestBody  ProductSkuVO productSkuVO) {
        return productService.updateBySVO(productSkuVO);

    }

    @GetMapping("/getAllShops")
    @ApiOperation("后台获取所有商品接口")
    public ResultVO1 getAllShops(PageVo pageVo){
        System.out.println("后台获取所有商品接口 pageVo:" + pageVo);
        ResultVO1 resultVO1 = productService.getAllShops(pageVo);

        return resultVO1;
    }

}
